Public Class frmChonDanhMucTheoListBox
    Private m_strDanhMuc As String
    Private m_strDisplayMember As String
    Private m_strValueMember As String
    Private m_ValueMember As String
    Private m_DisplayMember As String
    Private m_FFValue As String


    Property ValueMember() As String
        Get
            Return m_ValueMember
        End Get
        Set(ByVal value As String)
            m_ValueMember = value
        End Set
    End Property

    Property DisplayMember() As String
        Get
            Return m_DisplayMember
        End Get
        Set(ByVal value As String)
            m_DisplayMember = value
        End Set
    End Property

    Public Sub New(ByVal strDanhMuc As String, ByVal strDM As String, ByVal strVM As String, ByVal ffvalue As String)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        m_strDanhMuc = strDanhMuc
        m_strDisplayMember = strDM
        m_strValueMember = strVM
        m_FFValue = ffvalue
    End Sub

    Private Sub frmChonDanhMucTheoListBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GetListBoxDanhMuc()
    End Sub

    Private Sub GetListBoxDanhMuc()

        Dim ds As DataSet
        ds = BaseDB.ExecSql_DataSet(m_strDanhMuc)
        Dim dv As New DataView(ds.Tables(0))
        dv.Sort() = m_strDisplayMember
        lbxDanhMuc.DataSource = dv
        lbxDanhMuc.DisplayMember = m_strDisplayMember
        lbxDanhMuc.ValueMember = m_strValueMember
        lbxDanhMuc.Focus()
        Dim i As Integer = lbxDanhMuc.FindString(m_FFValue)
        'i = dv.Find(m_FFValue)
        If (i <> -1) Then
            lbxDanhMuc.SelectedIndex = i
        Else
            lbxDanhMuc.Focus()
        End If
    End Sub

    Private Sub lbxDanhMuc_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbxDanhMuc.DoubleClick
        m_ValueMember = lbxDanhMuc.SelectedValue
        m_DisplayMember = lbxDanhMuc.Text
        Me.Close()
    End Sub

    Private Sub lbxDanhMuc_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lbxDanhMuc.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            m_ValueMember = lbxDanhMuc.SelectedValue
            m_DisplayMember = lbxDanhMuc.Text
            Me.Close()
        End If
    End Sub
End Class